#include <iostream>
#include <vector>
#include <string>
using namespace std;

int min_insertion(string &s, int l, int r, vector<vector<int>> &dp)
{
        if(dp[l][r] != -1){
                return dp[l][r];
        }

        if(l > r){
                return dp[l][r] = 0;
        }
        if(l == r){
                return dp[l][r] = 1;
        }
        
        int p1 = INT32_MAX;
        if((s[l] == '[' && s[r] == ']') ||  (s[l] == '(' && s[r] == ')')){
                p1 = min_insertion(s, l + 1, r - 1, dp);
        }

        int p2 = min(min_insertion(s, l + 1, r, dp), min_insertion(s, l, r - 1, dp)) + 1;

        return dp[l][r] = min(p1, p2);
}

int main()
{
        string s;
        cin >> s;
        int n = s.size();
        vector<vector<int>> dp(n, vector<int>(n, -1));
        cout<<min_insertion(s, 0, n - 1, dp)<<endl;
        return 0;
}